/**
 * 借款报销 保存
 */

function JkbxSave(){
	if(window.$refEnterCount != null && window.$refEnterCount != 0){
		window.$pfsaveRt = setTimeout("PFBillEventHandler.delaySave()", 50);
		return;
	}  
	var oThis = this;
	var headDs = this.getMasterDs();
	var allSubDsArr = this.getAllSlaveDs();
    log("PF--->进入PFBillEventHandler.onBoSave()方法.");  
	if(!this.isNeedSave([headDs]) && !this.isNeedSave(allSubDsArr)) {
		if(!this.isTmpSaveStatus(headDs)){//是否时暂存态 保存，暂存态可以不修改直接保存
		    showMessageDialog(trans("ml_nooperation"));
		    return;
		}
	} 
	if(headDs != null)
		headDs.reqParameterMap.clear();
     
	for(var i = 0;i < allSubDsArr.length; i++) {
		if(allSubDsArr[i] != null)
       		allSubDsArr[i].reqParameterMap.clear();
	}
	var sRow = headDs.getSelectedRow();
   	// 主表校验不过,则不提交
   	if(!this.checkMasterDs(headDs, sRow))
   		return;
   	// 对所有子表进行提交前校验,如果校验不过,则不提交	
   	if(!this.checkDetailDs(allSubDsArr))
   		return;
	log("PFonBoSave方法中执行onbeforeAction()之前...");
	if(this.beforeAction(IPfAction.COMMIT) == false)
		return;
	log("PFonBoSave方法中执行完onbeforeAction()之后...");
	
	//保存前检查是否有指派
	oThis.checkIsAssign(headDs,allSubDsArr,"commit"); 
	
}

//具体实现保存的方法
PFBillEventHandler.prototype.JkbxSaveImpl = function(pksmap){
	var oThis = this;
	var headDs = this.getMasterDs();
	var allSubDsArr = this.getAllSlaveDs();
	if(headDs != null)
		headDs.reqParameterMap.clear();
	for(var i = 0;i < allSubDsArr.length; i++) {
		if(allSubDsArr[i] != null)
       		allSubDsArr[i].reqParameterMap.clear();
	}
	var sRow = headDs.getSelectedRow();
	
	// 显示进度提示对话框
	showProgressDialog(trans('ml_wait'));
	// 设置单据状态为【提交】(因为财务的保存和提交是一块的)
	sRow.setCellValue(headDs.nameToIndex(billUI.billController.billStatusField), this.getBillStatusValue("COMMIT"));
	//保存时可传递参数
	if(typeof window.objs == 'undefined')
		window.objs = null;
	var saver = new DatasetSaver();
	saver.setMasterDs(headDs);
	saver.setMasterRow(sRow);
	saver.setDetailDsArray(allSubDsArr);
	saver.setHaveDsRelation(true);
	saver.setReturnFunc(this.WebbxPfSaveShowDialog);
	saver.setReturnArgs([this,headDs]);
	saver.setSaveParam("obj=" + window.objs +"&ASSIGN_INFO=" + pksmap);
	saver.save();
	
};

PFBillEventHandler.prototype.WebbxPfSaveShowDialog = function(args, isSuccess)
{
	hideProgressDialog();
	var oThis = args[0];
	var headDs = args[1];
	oThis.saveSucessFun(args, isSuccess);
	log("PF--->成功执行完saveSunccessFun()函数");
	if(isSuccess){	
		// 正确执行完保存操作后,对所有的Dataset进行clearState操作
		oThis.callAllDsClearStatus();
	    oThis.billUI.setTotalUIStatus(IBillOperate.OP_NOTEDIT);
	    if(oThis.afterAction(IPfAction.COMMIT) == false)
			return;
	    window.objs = null;
	}else{
		headDs.setValueAt(headDs.getSelectedIndex(),headDs.nameToIndex('djzt'),null);
	}
		
	oThis.onAfterBoSave();
    log("PF保存执行完毕");	
};